
local xunxun = fk.CreateSkill{
  name = "mini__xunxun",
}

Fk:loadTranslationTable{
  ["mini__xunxun"] = "恂恂",
  [":mini__xunxun"] = "摸牌阶段开始时，你可以观看牌堆顶的四张牌，将其中两张牌以任意顺序置于牌堆顶，其余以任意顺序置于牌堆底。"..
  "结束阶段，你获得牌堆底的两张牌。",

  ["#mini__xunxun"] = "恂恂：将两张牌置于牌堆顶，其余牌置于牌堆底",

  ["$mini__xunxun1"] = "吾乃儒雅之士，不需与诸将争功。",
  ["$mini__xunxun2"] = "读诗书，尚礼仪，守纲常。",
}

xunxun:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(xunxun.name) and
      (player.phase == Player.Draw or player.phase == Player.Finish)
  end,
  on_cost = function (self, event, target, player, data)
    if player.phase == Player.Draw then
      return player.room:askToSkillInvoke(player, {
        skill_name = xunxun.name,
      })
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.phase == Player.Draw then
      local ret = room:askToArrangeCards(player, {
        skill_name = xunxun.name,
        card_map = { room:getNCards(4), "Top", "Bottom" },
        prompt = "#mini__xunxun",
        free_arrange = true,
        max_limit = {4, 2},
        min_limit = {0, 2},
      })
      local top, bottom = ret[1], ret[2]
      for i = #top, 1, -1 do
        table.removeOne(room.draw_pile, top[i])
        table.insert(room.draw_pile, 1, top[i])
      end
      for i = 1, #bottom, 1 do
        table.removeOne(room.draw_pile, bottom[i])
        table.insert(room.draw_pile, bottom[i])
      end
      room:syncDrawPile()
      room:sendLog{
        type = "#GuanxingResult",
        from = player.id,
        arg = #top,
        arg2 = #bottom,
      }
    else
      room:moveCardTo(room:getNCards(2, "bottom"), Card.PlayerHand, player, fk.ReasonJustMove, xunxun.name, nil, false, player)
    end
  end,
})

return xunxun
